<template>
	<view class="beijingse mainpadding">
		<u-picker :show="show" :title="title" keyName="name" :columns="columns" @confirm="confirm" @cancel="show=false"
			confirmColor="#FAB536"></u-picker>
		<view class="">
			<!-- 订单状态 -->
			<view class="bigtext">{{dataAll.logistics.status}}</view>
		</view>
		<!--订单时间状态  -->
		<view class="margin_top1">
			<view class="strongtext ">{{dataAll.logistics.context}}</view>
			<!-- <view class="strongtext ">请您耐心等待商家发货~</view> -->
			<!-- <view class="strongtext ">订单将于2022-12-29 16:30:20 自动确认收货</view> -->
			<!-- <view class="strongtext ">感谢您的支持，欢迎下次购买！</view> -->
			<!-- <view class="strongtext ">商家正在处理中~</view> -->
			<!-- <view class="strongtext ">您已发起换货申请等待商家审核！</view> -->
			<!-- <view class="strongtext ">卖家已同意您的申请请将商品寄回！</view> -->
			<!-- <view class="strongtext ">商家确认收货会将您的金额退回！</view> -->
			<!-- <view class="strongtext ">您的金额已原路退回，请注意查收！</view> -->
		</view>
		<!-- 地址 -->
		<view class="mainpadding ffffff radius margin_top">
			<view class="flexbetween">
				<view class="">
					<view class="flexleft">
						<view class="titletext margin_right3">{{dataAll.address.name}}</view>
						<view class="titletext">{{dataAll.address.mobile}}</view>
					</view>
					<view class="huisetext margin_top2">{{dataAll.address.address}}{{dataAll.address.address_name}}
					</view>
				</view>
				<view class="righticon"></view>
			</view>
		</view>
		<!-- 寄回地址 -->
		<!-- <view class="mainpadding ffffff radius margin_top">
			<view class="titletext">寄回地址</view>
			<view class="flexleft margin_top2">
				<view class="titletext margin_right3">张三</view>
				<view class="titletext">13112341234</view>
			</view>
			<view class="huisetext margin_top2">北京市丰台区优橙创新中心A座2021</view>
		</view> -->
		<!-- 换货金额 -->
		<!-- <view class="mainpadding ffffff radius margin_top flexbetween">
			<view class="titletext">换货金额</view>
			<view class="qianshu">￥98.00</view>
		</view> -->
		<!-- 快递单号 -->
		<!-- <view class="mainpadding ffffff radius margin_top">
			<view class="flexbetween">
				<view class="titletext">快递公司</view>
				<view class="notitletext">申通快递</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="titletext">快递单号</view>
				<view class="notitletext">46546456123132132123</view>
			</view>
		</view> -->
		<!-- 商品 -->
		<view class="ffffff mainpadding radius margin_top">
			<!-- 退货商品 -->
			<!-- <view class="titletext">退货商品</view> -->
			<view class="flexleft">
				<view class="haungfz margin_right1"></view>
				<view class="titletext margin_right2">{{dataAll.shop.name}}</view>
				<view class="righticon"></view>
			</view>
			<view class=" xiahuax margin_top" v-for="item in dataAll.goods" :key="item.id">
				<view class="flexbetween">
					<view class="shilitu">
						<image :src="item.image_text" mode=""></image>
					</view>
					<view class="" style="width: 74%;">
						<view class="ershib yhxiank">{{item.title}}</view>
						<view class="ershib margin_top1 yhxiank">{{item.difference}}</view>
						<view class="flexbetween margin_top1">
							<view class="qianshu" v-if="dataAll.buy_type==1">¥{{item.price}}</view>
							<view class="qianshu" v-if="dataAll.buy_type==2">¥{{item.fl_price}}</view>
							<view class="qianshu" v-if="dataAll.buy_type==3">¥{{item.fl_price}}福利券+{{item.price}}现金
							</view>
							<view class="shuliang">*{{item.number}}</view>
						</view>
					</view>
				</view>
				<view class="flexright margin_top">
					<!--退货/售后-->
					<view class="huisebtn" v-if="item.refund_status==0&& dataAll.state==3"
						@click="tzsqtk(item.id,item.order_id)">退货/售后</view>
					<!-- 换货中 -->
					<view class="huangsebtn" v-if="item.refund_status==1">换货中</view>
					<!-- 待退货 -->
					<view class="huangsebtn" v-if="item.refund_status==2">待退货</view>
					<!-- 换货完成 -->
					<view class="huangsebtn" v-if="item.refund_status==3">换货完成</view>
					<!-- 换货被拒 -->
					<view class="huangsebtn margin_right3" v-if="item.refund_status==5">换货被拒</view>
					<!-- 立即评价 -->
					<view class="huisebtn" v-if="item.comment_status==1 && dataAll.state==4" @click="tzfbpj(item.id)">
						立即评价</view>
				</view>
			</view>
		</view>
		<!-- 商品详情 -->
		<view class="paddingbom">
			<view class="ffffff mainpadding radius margin_top">
				<view class="flexbetween">
					<view class="ershil">商品金额</view>
					<view class="huisetext">¥{{dataAll.total_price}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil">运费</view>
					<view class="huisetext">¥{{dataAll.freight_price}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil">订单编号</view>
					<view class="huisetext">{{dataAll.order_no}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil">下单时间</view>
					<view class="huisetext">{{dataAll.createtime_text}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil">支付方式</view>
					<view class="huisetext">{{dataAll.pay_type_text}}</view>
				</view>
			</view>
		</view>

		<!-- 固定底部 -->
		<view class="gudingdb ffffff">
			<view class="flexright">
				<view class="huisebtn margin_right3" v-if="dataAll.state==1" @click="cancelorder">
					取消订单</view>
				<view class="huisebtn margin_right3" v-if="dataAll.state==3" @click="showmodal=true">查看物流</view>
				<view class="huangsebtn" v-if="dataAll.state==1" @click="atoncepay">立即支付</view>
				<view class="huangsebtn" v-if="dataAll.state==3" @click="suresh">确认收货</view>
				<view class="huisebtn margin_right3" v-if="dataAll.state==6 || dataAll.state==7" @click="deletorder">
					删除订单</view>
				<view class="huangsebtn" v-if="dataAll.state==6">再次购买</view>
			</view>
		</view>

		<u-modal :show="showmodal" title="物流信息" confirmText="点击复制" @close="showmodal=false" :closeOnClickOverlay="true"
			@confirm="modalconfirm" confirmColor="#FAB536">
			<view class="mainpadding">
				<view class="margin_top flexcenter strongtext">{{dataAll.express_no}}</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				dataAll: {
					address: {
						address: "",
						address_name: "",
						id: 0,
						mobile: "",
						name: "",
					},
					address_id: 0,
					buy_type: 0,
					cancelyy: "",
					coupon_id: 0,
					createtime_text: "",
					freight_price: "",
					freight_type: 0,
					goods: [{
						actual_payment: "",
						comment_status: "",
						difference: "",
						discount_price: "",
						fl_price: "",
						freight_price: "",
						goods_id: 0,
						goods_sku_id: 0,
						goods_sku_sn: "",
						id: 0,
						image: "",
						image_text: "",
						market_price: "",
						number: 0,
						order_id: 0,
						price: "",
						refund_id: 0,
						refund_status: "",
						shop_id: 0,
						shop_name: "",
						status: "",
						title: "",
						total_fl_price: null,

					}],
					id: 0,
					integral_price: "",
					isaddress: 0,
					logistics: {
						context: "",
						status: "",
						time: "",
					},
					order_no: "",
					order_pay_no: "",
					pay_price: "",
					pay_status: "",
					pay_time: 0,
					pay_type: "",
					pay_type_text: "",
					paymenttime: 0,
					paymenttime_text: "",
					remarks: "",
					shop_id: 0,
					state: 0,
					status: "",
					taketime: null,
					taketime_text: "",
					total_price: "",
					updatetime: 0,
					user_id: 0,
					shop: {
						name: ""
					}
				},
				show: false,
				title: "选择取消理由",
				columns: [],

				showmodal: false,
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getliyou()
		},
		onShow() {
			this.init()
		},

		methods: {
			// 订单取消理由
			getliyou() {
				httpRequest.request('/api/order/orderCancelly', 'POST', {}, false, false, true).then(res => {
					this.columns.push(res.data)
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			init() {
				httpRequest.request('/api/order/getOrderInfo', 'POST', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			cancelorder() {
				this.show = true
			},
			// 立即支付
			atoncepay() {
				let obj = {
					buy_type: 1,
					order_pay_no: this.dataAll.order_pay_no,
					pay_price: this.dataAll.pay_price,
				}
				uni.navigateTo({
					url: '/pages/homepage/querenddzhzf?msg=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			// 确认收货
			suresh() {
				httpRequest.modal('提示', '请再次确认', true, (res) => {
					if (res) {
						httpRequest.request('/api/order/confirmOrder', 'POST', {
							id: this.listid,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 取消订单
			confirm(e) {
				let url = ""
				if (this.dataAll.buy_type == 3) {
					url = "/api/order/cancelOrder1"
				} else {
					url = "/api/order/cancelOrder"
				}
				httpRequest.request(url, 'POST', {
					order_id: this.listid,
					cancelyy_id: e.value[0].id
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
				this.show = false
			},
			// 删除订单
			deletorder() {
				httpRequest.modal('提示', '确定删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/order/delOrder', 'POST', {
							id: this.listid,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								uni.navigateBack(1)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 跳转申请换货
			tzsqtk(id, order_id) {
				let data = {
					listid: id,
					order_id: order_id
				}
				uni.navigateTo({
					url: '/pages/mypage/shenqtk?msg=' + encodeURIComponent(JSON.stringify(data))
				})
			},
			// 跳转立即评价
			tzfbpj(id) {
				uni.navigateTo({
					url: '/pages/mypage/fabiaoqj?id=' + id
				})
			},
			// 跳转填写单号
			tztxdh() {
				uni.navigateTo({
					url: '/pages/mypage/tianxdh'
				})
			},
			// 查看物流确认
			modalconfirm() {
				this.showmodal = false
				uni.setClipboardData({
					data: this.dataAll.express_no, //要被复制的内容
					success: () => { //复制成功的回调函数
						httpRequest.toast("复制成功")
					}
				});
			},
			// 跳转查看物流
			tzckwl() {
				uni.navigateTo({
					url: '/pages/mypage/wuliuxq'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.xzqianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FAB536;
	}

	.huangsebtn {
		border: 2rpx solid #FAB536;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FAB536;
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.yhxiank {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.paddingbom {
		padding-bottom: 200rpx;
	}
</style>
